﻿using System;
using System.Collections.Generic;
using System.Linq;
using Medianamik.Core;
using Medianamik.Core.Security;
using Medianamik.Core.Sugar;

namespace Medianamik.UI.Web.TypeList.Data
{
    public static class Utilities
    {
        public static IList<NodeType> GetListableTypes()
        {
            return NodeTypeManager.GetAllTypes(false)
                .Where(t => !t.IsSystem && t.Listable && Roles.UserHasRight(t, SecurityLevels.Create))
                .OrderBy(t => t.LocalizedName)
                .ToList();
        }

        public static Guid? ValidateGuid(this Guid? guid)
        {
            if (guid != null)
                StringHelper.IsGuid(guid.ToString(), ref guid);
            return guid;
        }
    }
}
